﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace FourKill.Engine
{
    public class Tree : IPaintable
    {
        private static Tree _instance;
        public static Tree Instance { get { _instance = _instance ?? new Tree(); return _instance; } }

        public void Paint(IPaintableContext context)
        {
            if (context.GameObject.LocationRelativeToCamera == null)
                context.GameObject.UpdateLocation(context);
            var location = context.GameObject.LocationRelativeToCamera;

            if (location.IsVisible)
            {
                try
                {
                    using (SolidBrush sb = new SolidBrush(context.GameObject.Color))
                    {
                        Point p1 = new Point(location.ObjectRectangle.X + location.ObjectRectangle.Width / 2, location.ObjectRectangle.Y);
                        Point p2 = new Point(location.ObjectRectangle.X, location.ObjectRectangle.Y + location.ObjectRectangle.Height);
                        Point p3 = new Point(location.ObjectRectangle.X + location.ObjectRectangle.Width, location.ObjectRectangle.Y + location.ObjectRectangle.Height);
                        context.FrontLayer.FillPolygon(sb, new Point[] { p1, p2, p3 });
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("***********************************");
                    System.Diagnostics.Debug.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
    }
}
